package com.yc;

import com.alibaba.druid.pool.DruidDataSource;
import com.yc.DbConfig;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    @Bean
    @Primary
    @RefreshScope
    public DataSource dataSource(DbConfig dbConfig) {
        DruidDataSource ds = new DruidDataSource();
        ds.setUrl(dbConfig.getUrl());
        ds.setUsername(dbConfig.getUsername());
        ds.setPassword(dbConfig.getPassword());
        ds.setDriverClassName(dbConfig.getDriverClassName());
        return ds;
    }
}
